<script type="text/javascript">
Ext.namespace('catalog.catalog.teacherList');

catalog.catalog.teacherList.SearchPanel = Ext.extend(catalog.ComplexEditorGrid, {
lastName:'Nume',
userName:'Nume utilizator',
firstName:'Prenume',
discipline:'Disciplina',
classMaster:'Diriginte',
enabled:'Enabled',
bindRoles:'Bind Roles',
addUser:'Add User',
enableUsersButton:'Enable/Disable',
statusAccordConfMsg:'Please make sure users selected are all enabled or disabled!',
enableUsersConfMsg:'Are you sure want to enable the users?',
disableUsersConfMsg:'Are you sure want to disable the users?',

initComponent:function() {
var sm = new Ext.grid.CheckboxSelectionModel();
var config = {
compSet:[{url:0,reader:0,columns:0,bbarAction:0}],
searchFields :[[
            this.lastName, {xtype:'textfield', name:'teacherDTO.lastName', width:120}
            ]],
urls: ['findTeacher.action'],
readers : [[
            {name: 'userName'},
            {name: 'lastName'},
            {name: 'firstName'},
            {name: 'discipline'},
            {name: 'classMaster'}
            ]],
columnsArray: [[
            {header: this.userName, width: 100, sortable: true, dataIndex: 'userName'},
            {header: this.lastName, width: 100, sortable: true, dataIndex: 'lastName',
            editor: new Ext.form.TextField({allowBlank: false})},
            {header: this.firstName, width: 180, sortable: true, dataIndex: 'firstName'},
            {header: this.discipline, width: 90, sortable: true, dataIndex: 'discipline'},
            {header: this.classMaster, width: 70, sortable: true, dataIndex: 'classMaster'},
            sm
            ]],

bbarActions:[[{
            text:mbLocale.deleteButton,
            iconCls :'delete-icon',
            scope:this,
            handler:this.deleteUsersFun
            },{
            text:mbLocale.submitButton,
            iconCls :'save-icon',
            scope:this,
            handler:this.saveUserFun
            }]],
sm:sm
}; // eo config object
Ext.apply(this, Ext.apply(this.initialConfig, config));
catalog.catalog.teacherList.SearchPanel.superclass.initComponent.apply(this, arguments);
},

deleteUsersFun :function() {
                var teacherDTOIds = this.selModel.selections.keys;
                if (teacherDTOIds.length <= 0) {
                Ext.MessageBox.alert(mbLocale.infoMsg, mbLocale.gridMultRowSelectMsg);
                return;
                }
                var submitFun = function(buttonId, text, opt) {
                if (buttonId == 'yes') {
                catalog.util.ajaxRequest({
                url: 'deleteTeacher.action',
                params:{'teacherDTO.id':teacherDTOIds},
                success:function(r,o){
                var res = Ext.decode(r.responseText);
                if (res && res.success){
                this.store.reload();
                }
                },
                failure:Ext.emptyFn
                },this);
                }
                };
                Ext.Msg.show({
                title:mbLocale.infoMsg,
                msg: mbLocale.delConfirmMsg,
                buttons: Ext.Msg.YESNO,
                scope: this,
                fn: submitFun,
                icon: Ext.MessageBox.QUESTION
                });
                },
saveUserFun :function() {
            var store = this.getStore();
            if(store.getModifiedRecords().length != 1){
            Ext.MessageBox.alert(mbLocale.infoMsg, mbLocale.gridRowEditMsg);
            return;
            }
            var teacherDTO = store.getModifiedRecords()[0];
            var submitFun = function(buttonId, text, opt) {
            if (buttonId == 'yes') {
            catalog.util.ajaxRequest({
            url: 'updateTeacher.action',
            params:{'teacherDTO.id':teacherDTO.id,
            'teacherDTO.lastName':teacherDTO.get('lastName')}   ,
            success:function(r,o){
            this.store.commitChanges();
            },
            failure:Ext.emptyFn
            },this);
            }
            };
            Ext.Msg.show({
            title:mbLocale.infoMsg,
            msg: mbLocale.updateConfirmMsg,
            buttons: Ext.Msg.YESNO,
            scope: this,
            fn: submitFun,
            icon: Ext.MessageBox.QUESTION
            });
            }
 });


try {teacherListLocale();} catch (e) {}

Ext.onReady(function() {
            Ext.QuickTips.init();
            var formPanel = new catalog.catalog.teacherList.SearchPanel();
            formPanel.store.reload();
            if (mainPanel) {
            mainPanel.getActiveTab().add(formPanel);
            mainPanel.getActiveTab().doLayout();
            } else {
            var vp = new Ext.Viewport({
            layout:'fit',
            items:[formPanel]
            });
            }
            });
</script>